 <?php echo $this->load->view('_elements/registratednavigation'); ?>

<div id="content">

    <div id="centerbar">
        <div class="titlered"><?php echo $Title ?> (<span id="inboxmessages"><?php echo $number ?></span>)</div>
        <div id="tableblock" class="blockstyle">
            <table id="requestable" class="iTable" border="0" cellpadding="0" cellspacing="0" width="100%" style="color: inherit;">
            	<thead>
	            	<tr style="color: #507baf;">
	                    <th><input id="thead" type="checkbox" onclick="toggleCheckboxes($(this), 'requestable')"></input></th>
	                    <th><?php echo $this->inbox_model->fields['date_posted']?></th>
	                    <th><?php echo $this->inbox_model->fields['status']?></th>
	                    <th><?php echo $this->inbox_model->fields['sender']?></th>
	                    <th><?php echo $this->inbox_model->fields['message_header']?></th>
	                    <th><?php echo $this->inbox_model->fields['referral_no']?></th>
	                    <th><?php echo $this->inbox_model->fields['ask_price']?></th>
	                    <th><?php echo $this->inbox_model->fields['bid_price']?></th>
	                </tr>
	            </thead>
	            <tbody>
		            <?php 
		            	$i = 0;
		            	foreach($message as $key => $value) {
		            		$style = '2';
		            		if($value['inbox_read_status'] == 2) {
		            			$style = "style = 'color:#c00000'";
		            		} else if($value['inbox_read_status'] == 1) {
		            			$style = "style = 'color:#507baf;'";
		            		}
		            		echo "<tr ".$style." id=".$i." ondblclick='dclick(".$value['inbox_id'].")'>
				                    <td><input class='checkbox input".$i."' type='checkbox' value='".$value['inbox_id']."'></input></td>
				                    <td>".$value['inbox_date_posted']."</td>
				                    <td>".$value['inbox_status']."</td>
				                    <td>".$value['inbox_sender']."</td>
				                    <td>".$value['inbox_message_header']."</td>
				                    <td>".$value['inbox_referral_no']."</td>
				                    <td>".(($value['inbox_ask_price'] == null)?'':'$'.$value['inbox_ask_price'])."</td>
				                    <td>".(($value['inbox_bid_price'] == null)?'':'$'.$value['inbox_bid_price'])."</td>
				                </tr>";
		            		
		            		$i++;
		            	}
		            ?>
                </tbody>
            </table>
            
            <input id="deletebutton" class="buttonStyle" style="color: #bbb; border-color: #ddd" type="submit" name="delete" value="Delete" disabled="disabled"></input>
            
            <div class="redsimpletext rightps" >To open a message to read and/or reply simply double click anywhere in the target message row; to delete a message
												simply click one of more messages and delete button will be enabled.</div>
        </div>
    </div>

<?php echo $this->load->view('_elements/Followrefs'); ?>
</div>

<script type="text/javascript">

 var oTable;

 $(document).ready(function()
 {
  /* Init DataTables */
  	oTable = $('#requestable').dataTable(
  	{
  		"sDom": '<"top"i>rt<"bottom"flp><"clear">',
   		"aaSorting": [],
   		"aoColumns": [
      		{ "bSortable": false },
			null,
			null,
		    null,
		    null,
		    null,
            null,
            null
     	],

	   "bPaginate": true,
	   "bLengthChange": true,
	   "bFilter": false,
	   "bSort": true,
	   "bInfo": false,
	   "bAutoWidth": true,
	   "bJQueryUI": true,
	   "sPaginationType": "full_numbers"
  });

  		$('#requestable_paginate').append('<span id="page_text" class="red fg-button ui-button ui-state-default ui-state-disabled">Page </span>');
    	$('#requestable_first, #requestable_previous, #requestable_next, #requestable_last').hide();
        $(".dataTables_paginate span span.fg-button.ui-button.ui-state-default").parent().attr('id','leftnavigation');
 });

 /*
  * I don't actually use this here, but it is provided as it might be useful and demonstrates
  * getting the TR nodes from DataTables
  */
 function fnGetSelected( oTableLocal )
 {
  var aReturn = new Array();
  var aTrs = oTableLocal.fnGetNodes();

  for ( var i=0 ; i<aTrs.length ; i++ )
  {
   if ( $(aTrs[i]).hasClass('row_selected') )
   {
    aReturn.push( aTrs[i] );
   }
  }
  return aReturn;
 }

 </script>

<SCRIPT type="text/javascript">

	function deleteMessage(script, action, event) {


		items = serializeCheckboxes('requestable');
		//alert(items);
		startAnimation();	
		$('.msg').remove();
		$.post(
		  	script,
		  	{
				items: items||''
		  	},
		  	onAjaxSuccess
		);
		
		function onAjaxSuccess(data)
		{       
			$.each($('input'), function() {
				if($(this).attr('checked') == true && $(this).attr('id') != 'thead') {
					$(this).parent().parent().remove();
					$('#deletebutton').css('color', '#ddd').attr('disabled', true);
				} else if($(this).attr('id') == 'thead'){
					$(this).attr('checked', false);
				}
			});	

			finishAnimation();
			$.each($('#inboxmessages'), function() {
				var inbox = parseInt($(this).html())-1;
				if(inbox >= 0) {
					$(this).html(inbox);
					$('#inbox').html(' ! Inbox ('+inbox+') ');
				}
			});	
			$('#content').prepend('<p class="msg done">Data was removed succesfully.</p>');
			
		}
	}	
	
	$(function() {
  		$('tr input').click(function(){
			var black = '#ddd';
			var border = '#ddd';
			var disable = 'disabled';
			$.each($('input'), function() {
				if($(this).attr('checked') == true && $(this).attr('id') != 'thead') {
					black = '#000';
					border = '#7B9DBD';
					disable = false;
					return false;
				}
			});
			$('#deletebutton').css('color', black).attr('disabled', disable).css('border-color', border);
  	  	});
  		$('#deletebutton').click(function() {

  			if (confirm('Are you sure you want to delete these data?')) 
  				deleteMessage('/site/inbox/deleteItems/');$(this).location='/admin/users/delete/10';return false;
  	  		
  			/*
			});*/
  	  	});
  		//$('tbody tr').css('background', '#bee');
  	  	$('tbody tr').css('cursor','pointer').hover(
  	    	  	function(){
					$(this).css('background', '#bee');
  	  	    	},function(){
  	  	    	$(this).css('background', '#fff');
  	  	});
	});
	function dclick(id) {
		$(this).attr('location', 'inbox/view/'+id);
	}
</SCRIPT>